using System;

using Microsoft.Practices.Prism.Modularity;
using Microsoft.Practices.Prism.Regions;
using Microsoft.Practices.Unity;

using SearchModule.Views;
using SearchModule.Services;

namespace SearchModule
{
    public class ModuleInit : IModule
    {
        private readonly IUnityContainer _container;
        private readonly IRegionManager _regionManager;

        public ModuleInit(IUnityContainer container, IRegionManager regionManager)
        {
            _container = container;
            _regionManager = regionManager;
        }

        #region IModule Members

        public void Initialize()
        {
            _container.RegisterType<IDataService, DataService>(new ContainerControlledLifetimeManager());
            _regionManager.RegisterViewWithRegion("TopMainRegion", () => _container.Resolve<SearchInputView>());
            _container.RegisterType<Object, SearchInputView>("SearchInputView");

            // adding the search results view
            _regionManager.RegisterViewWithRegion("MainRegion", () => _container.Resolve<SearchResultsView>());
            _container.RegisterType<Object, SearchResultsView>("SearchResultsView");

            // register the generic web view type
            _container.RegisterType<Object, GenericWebView>("GenericWebView");
        }

        #endregion
    }
}
